package at.fhj.mobsecdev.cookit.util;

import android.text.TextUtils;
import android.widget.EditText;
import android.widget.LinearLayout;
import at.fhj.mobsecdev.cookit.model.Ingredient;

/**
 * Represents a EditText-tuple of Food and associated amount for input in Recipe Add Activity
 */
public class IngredientControlTuple {
	
	private LinearLayout layout;
	
	private EditText amount;
	private EditText ingredient;
	
	/* Protected constructor, so that only factory can create object */
	protected IngredientControlTuple(LinearLayout layout, EditText amount,
			EditText ingredient) {
		super();
		this.layout = layout;
		this.amount = amount;
		this.ingredient = ingredient;
	}

	public EditText getIngredient() {
		return ingredient;
	}
	
	public void setIngredient(EditText ingredient) {
		this.ingredient = ingredient;
	}
	
	public EditText getAmount() {
		return amount;
	}
	
	public void setAmount(EditText amount) {
		this.amount = amount;
	}

	public LinearLayout getLayout() {
		return layout;
	}

	public void setLayout(LinearLayout layout) {
		this.layout = layout;
	}
	
	/**
	 * Returns ingredient that is associated with this tuple
	 * @return the ingredient object or null, if no ingredient is associated
	 */
	public Ingredient generateIngredient()
	{
		Ingredient ingredientObject = new Ingredient();
		
		String amountInput = amount.getText().toString();
		String ingredientInput = ingredient.getText().toString();
		
		if(!TextUtils.isEmpty(amountInput))
		{
			ingredientObject.setAmount(amountInput);
		}
		else
		{
			return null;
		}
		
		if(!TextUtils.isEmpty(ingredientInput))
		{
			ingredientObject.setFood(ingredientInput);
		}
		else
		{
			return null;
		}
		
		return ingredientObject;
	}
}
